package com.webservice.dao.Stockinfodao.impl;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.webservice.dao.PubBaseDao;
import com.webservice.dao.Stockinfodao.IStockInfoDao;
import com.webservice.utils.DateTimeTool;
import com.webservice.utils.UUIDUtil;
import com.webservice.vo.impl.StockInventoryinfoVo;
import com.webservice.vo.impl.StockinfoVo;

/**
 * 
* @ClassName: StockInfoDaoImpl
* @Description: 库存同步接口私有类,继承PubBaseDao公共类
* @author A18ccms a18ccms_gmail_com
* @date 2013-12-16 下午4:38:44
*
 */
@Repository("stockInfoDao")
public class StockInfoDaoImpl extends PubBaseDao implements IStockInfoDao {
	@Autowired
	@Qualifier("datatemplate")
	private JdbcTemplate jdbcTemplate;
	
	private static Logger logger = Logger.getLogger(PubBaseDao.class);
	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}
	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}
	/**
	 * (非 Javadoc)
	* <p>Title: InsertStockInfo</p>
	* <p>插入库存信息 </p>
	* @param stockInfoVo
	* @return
	* @see com.webservice.dao.Stockinfodao.IStockInfoDao#InsertStockInfo(com.webservice.vo.impl.StockinfoVo)
	 */
	@Override
	public int InsertStockInfo(final StockinfoVo stockInfoVo) {
		String strsql="INSERT INTO OT_STORE(PK_STORE,STORCODE,ITEMCODE,PACKNUM,PUTAWAYNUM,SYNCTIME)" +
				"VALUES(?,?,?,?,?,?)";
		
		final List<StockInventoryinfoVo> stockinventoryinfolist=stockInfoVo.getProducts();
	       int[] updateCounts = jdbcTemplate.batchUpdate(strsql,  new BatchPreparedStatementSetter() {  
               public int getBatchSize() {  
                   return stockinventoryinfolist.size();    
               }
				public void setValues(
						java.sql.PreparedStatement ps, int i)
						throws SQLException {
				   ps.setString(1, UUIDUtil.getUUID());
				   ps.setString(2, stockInfoVo.getStorcode());
				   ps.setBigDecimal(3, ((StockInventoryinfoVo)stockinventoryinfolist.get(i)).getProductcode());
				   ps.setBigDecimal(4, ((StockInventoryinfoVo)stockinventoryinfolist.get(i)).getPacknum());
				   ps.setBigDecimal(5, ((StockInventoryinfoVo)stockinventoryinfolist.get(i)).getPutawaynum());
                   ps.setString(6, (DateTimeTool.getDateTimeString(new Date())));
				}
           } );  
	       return updateCounts.length; 
	}

}
